using System;
using System.IO;

namespace SoftwareMonkeys.Scriptech.Projects
{
	public class ProjectAssemblyReferencer
	{
		static public string GetReferencePath(string referencedAssembly, string buildMode, string storeName, string groupName, string projectName)
		{
			Project project = ProjectReader.GetProject(storeName, groupName, projectName);
			
			string path = String.Empty;
			
			if (referencedAssembly.IndexOf(project.Name) > -1)
				path = GetProjectRelatedReferencePath(referencedAssembly, buildMode, storeName, groupName, project);
			else
				path = Path.GetFileNameWithoutExtension(referencedAssembly);
			
			return path;
		}
		
		static private string GetProjectRelatedReferencePath(string referencedAssembly, string buildMode, string storeName, string groupName, Project project)
		{
			string projectPath = ProjectFileNamer.GetProjectPath(storeName, groupName, project.Name);
			
			string binDirectoryPath = Path.Combine(projectPath, "bin");
			
			string modeDirectoryPath = Path.Combine(binDirectoryPath, buildMode);
			
			string path = Path.Combine(modeDirectoryPath, Path.GetFileName(referencedAssembly));
			
			return path;
		}
	}
}

